#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
double a[N];
struct Node {
  double s, s2, d;
} tr[N << 2];

void pushup(int p) {
  tr[p].s = tr[p << 1].s + tr[p << 1 | 1].s;
  tr[p].s2 = tr[p << 1].s2 + tr[p << 1 | 1].s2;
}
void addtag(double d, int p, int l, int r) {
  tr[p].d += d;
  tr[p].s2 += d * d * (r + 1 - l) + 2 * d * tr[p].s;
  tr[p].s += d * (r + 1 - l);
}
void pushdown(int p, int l, int r) {
  if (tr[p].d) {
    int mid = (l + r) >> 1;
    addtag(tr[p].d, p << 1, l, mid);
    addtag(tr[p].d, p << 1 | 1, mid + 1, r);
    tr[p].d = 0;
  }
}
void build(int p, int l, int r) {
  tr[p].d = 0;
  if (l == r) {
    tr[p].s = a[l];
    tr[p].s2 = a[l] * a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int L, int R, double d, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(d, p, l, r);
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, d, p << 1, l, mid);
  if (R > mid) update(L, R, d, p << 1 | 1, mid + 1, r);
  pushup(p);
}
Node query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return tr[p];
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  Node res{0, 0, 0};
  if (L <= mid) {
    Node x = query(L, R, p << 1, l, mid);
    res.s += x.s;
    res.s2 += x.s2;
  }
  if (R > mid) {
    Node x = query(L, R, p << 1 | 1, mid + 1, r);
    res.s += x.s;
    res.s2 += x.s2;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    int op, L, R;
    double d;
    cin >> op >> L >> R;
    if (L > R) swap(L, R);
    if (op == 1) {
      cin >> d;
      update(L, R, d, 1, 1, n);
    } else {
      Node res = query(L, R, 1, 1, n);
      int len = (R + 1 - L);
      double ex = res.s / len;
      double ex2 = res.s2 / len;
      if (op == 2)
        cout << fixed << setprecision(4) << ex << endl;
      else
        cout << fixed << setprecision(4) << ex2 - ex * ex << endl;
    }
  }
  return 0;
}